package LeetCode;

public class LC_050_Powxn {
    public static void main(String[] args) {

    }

    static class Solution {
        public double myPow(double x, int n) {
            if (x == 1.0)
                return x;

            double sum = 1;
            double temp = x;
            boolean flag = false;

            if (n < 0) {
                flag = true;
                n = -n;
            }

            while (n != 0) {
                if (n % 2 == 1)
                    sum = sum * temp;
                temp = temp * temp;
                n = n >>> 1;
            }
            if (!flag)
                return sum;
            else
                return 1 / sum;
        }
    }

    static class Solution_2 {
        public double pow(double x, int n) {
            return Math.pow(x, n);
        }
    }
}
